<template>
  <headVue name="我的进货单"></headVue>
  <main v-if="cardProduceList === [] ? false : true">
    <div class="compance" v-for="item in cardProduceList">
      <div class="littop">河南伊顺苑实业有限公司</div>
      <div class="box">
        <div class="img">
          <img
            :src="item.img1"
          />
        </div>
        <div class="con">
          <p>
            {{item.title}}
          </p>
          <p class="price">
            <div class="price_inner">¥{{item.price}}</div>
            <div class="num">x{{item.buyNum}}/件</div>
          </p>
          </div>
      </div>
      <div class="btnbox">
        <button @click="delProduc(item.id)">删除</button>
        <button>移入收藏夹</button>
        <div style="clear:both;"></div>
      </div>
    </div>
  </main>
  <div v-else>
    <p>购物单已空</p>
  </div>
</template>

<script>
import headVue from "@/components/head.vue";

export default {
  name: "cartList",
  data() {
    return {
      cardProduceList: [],
    };
  },
  components: {
    headVue,
  },
  mounted() {
    const list = JSON.parse(localStorage.getItem("cardList"));
    this.cardProduceList = list;
  },
  methods: {
    delProduc(id) {
      this.cardProduceList = this.cardProduceList.filter(
        (item) => item.id !== id
      );
      localStorage.setItem("cardList", JSON.stringify(this.cardProduceList));
    },
  },
};
</script>

<style scoped>
main {
  width: 100%;
  height: 100%;
  padding: 10px;
  background-color: #f7f7f7;
}
.compance {
  background: #fff;
  border-radius: 5px;
  margin-bottom: 10px;
  box-shadow: 0 0 5px #e1e1e1;
  padding: 5px 6px 6.4px;
}
.box {
  margin: 4px 0 3.6px;
  padding: 10px 0 5.8px;
  border-top: 1px dotted #ccc;
  border-bottom: 1px dotted #ccc;
  display: flex;
  align-items: center;
}
img {
  width: 50px;
}
.con {
  padding-left: 10px;
  flex: 1;
}
.price {
  width: 100%;
  margin-top: 10px;
}
.price_inner {
  float: left;
  color: #1a9956;
}
.num {
  float: right;
}
button {
  display: inline-block;
  width: 100px;
  height: 30px;
  line-height: 9.6px;
  text-align: center;
  color: #999;
  border: 1px solid #999;
  border-radius: 1px;
  margin-top: 10px;
  margin-left: 2px;
  margin-bottom: 4px;
  float: right;
}

</style>